Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
Why function with name "clear" doesn't work in JavaScript

I wrote a small HTML file. I added few buttons with onclick attributes and wrote my functions inside a "script" tag. All of them are working perfect but the function with name "clear" doesn't work.

HTML:

<div>
  <input type="button" value="Copy" onclick="copy();" />
  <input type="button" value="Clear" onclick="clear();" />
</div>

JavaScript:

  function copy() {
    console.log("copy");
    navigator.clipboard.writeText(
      document.getElementById("result_box").value
    );
  }

  function clear() {
    console.log("clear");
  }

When I click on both of this buttons browser console shows me only one message: "copy". No errors.

If I change the name of this function it starts working. I don't understand why is it happening. I thought the word "clear" is reserved word of JavaScript but I couldn't find this word in the list of keywords in documentation. Any ideas?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The reasoning behind this is that clear() inside a button calls document.clear instead of your clear.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!